package LC;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @ClassName LC17
 * @Description: TODO
 * @Author hl
 * @Date 2021/3/28
 * @Version V1.0
 **/
public class LC17 {
    public static void main(String[] args) {
        List<String> res=letterCombinations("23");
        System.out.println(res.toString());
    }
    public static List<String> letterCombinations(String digits) {
        List<String> res=new ArrayList<>();
        if(digits.length()==0) return res;
        HashMap<Character,String> map=new HashMap<>();
        map.put('2',"abc");
        map.put('3',"def");
        map.put('4',"ghi");
        map.put('5',"jkl");
        map.put('6',"mno");
        map.put('7',"pqrs");
        map.put('8',"tuv");
        map.put('9',"wxyz");
        backGetString(map,digits,0,res,new StringBuffer());
        return res;
    }
    public static void backGetString(HashMap<Character, String> map, String digits, int index, List<String> res, StringBuffer str){
        if(str.length()==digits.length()) {
            res.add(str.toString());
            return;
        }

        String target=map.get( digits.charAt(index));
        for(int i=0;i<target.length();i++){
            str.append(target.charAt(i));
            backGetString(map,digits,index+1,res,str);
            str.deleteCharAt(index);
        }

    }
}
